package com.jr.controller;


import com.jr.entity.Flighttickets;
import com.jr.pojo.FlightInfo;
import com.jr.pojo.Search;
import com.jr.service.IFlightsService;
import com.jr.service.IFlightticketsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.thymeleaf.standard.processor.StandardEachTagProcessor;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-10-05
 */
@RestController
@RequestMapping("/flights/")
public class FlightsController {
    // 假设FlightService是包含了selectAll()方法的业务逻辑服务类
    @Autowired
    private IFlightsService flightService;

    @Autowired
    private IFlightticketsService lightticketsService;

    /**
     * 获取航班信息列表。
     *根据航班日期，起飞城市，降落城市查询
     * @return 航班信息列表
     */
    @GetMapping("search")
    public ResponseEntity<List<FlightInfo>> searchFlights(Search search) {

        // 调用服务层的方法来获取航班信息
        List<FlightInfo> flights = flightService.findAll(search);
        System.out.println(search+"================================================================");
        // 返回查询结果
        System.out.println(flights);
        return ResponseEntity.ok(flights);
    }

    /**
     * 根据航班ID获取航班信息。
     * @param id 航班ID
     * @return 航班信息
     */
    @GetMapping("searchById")
    public List<Flighttickets> getFlightById(Integer id) {
        List<Flighttickets> flight = lightticketsService.selectById(id);
        System.out.println(flight);
        if (flight == null) {
            return flight;
        }
        return flight;
    }

}
